package com.example.meitu.api.common;

import java.time.*;

public class DateUtils {
    public static LocalDate timeConvertLocaldate(int time){
        LocalDateTime localDateTime = LocalDateTime.ofEpochSecond(time, 0, ZoneOffset.ofHours(8));
        return localDateTime.toLocalDate();
    }

    public static Integer localdateConvertTime(LocalDate localDate){
        ZoneId zone = ZoneId.systemDefault();
        long timestamp = localDate.atStartOfDay().atZone(zone).toInstant().toEpochMilli();
        return (int)(timestamp/1000);
    }

    public static Integer lastDayStart(){
        ZoneId zone = ZoneId.systemDefault();
        long timestamp = LocalDate.now().minusDays(1).atStartOfDay().atZone(zone).toInstant().toEpochMilli();
        return (int)(timestamp/1000);
    }

    public static Integer lastDayEnd(){
        ZoneId zone = ZoneId.systemDefault();
        long timestamp = LocalDate.now().atStartOfDay().minusSeconds(1).atZone(zone).toInstant().toEpochMilli();
        return (int)(timestamp/1000);
    }

    public static void main(String[] args) {
        //2024-06-26
        int timestamp = 1719331200;
        System.out.println(Instant.ofEpochSecond(timestamp).atZone(ZoneOffset.ofHours(8)).toLocalDate());
        LocalDate localDate = Instant.ofEpochSecond(timestamp).atZone(ZoneOffset.ofHours(8)).toLocalDate();

        localDate = LocalDate.of(2024,06,28);
        long timestamp2 = localdateConvertTime(localDate);
        System.out.println(timestamp2);
    }

}
